#include <stdio.h>
#include <stdlib.h>

#define MAX_I 31268

int getNum(unsigned   long n, int len);

unsigned long max(unsigned long a, unsigned long b)
{
    return a > b ? a : b;
}
unsigned   long getDigits(unsigned   long n)
{
    unsigned   long ix = 10;
    unsigned   long iy = 1;

    if(n< 10)
        return n;

    while(n / ix >= 1)
    {
        ix *= 10;
        iy++;
    }
    ix /= 10;
    return getDigits(ix-1) + (n - ix + 1) * iy;

}

unsigned long getLenOfN(unsigned long n)
{
    unsigned long l =0 ;
    unsigned long sum = 0;
    unsigned long temp = 0;

    for(l = 1; ; l++)
    {
        if(l < 10)
            temp= 1;
        else if(l < 100)
            temp= 2;
        else if(l < 1000)
            temp= 3;
        else if(l < 10000)
            temp= 4;
        else if(l < MAX_I)//31267
            temp= 5;
        if(n > sum && n <= sum +temp)
            break;
        sum += temp;
    }
    return getNum(l, sum+temp-n);
}

int getNum(unsigned   long n, int len)
{
    unsigned long ix = n, iy = 1, in = 0;

    for(in = 0; in < len; in++)
        iy *= 10;

    return (ix / iy)%10;
}

void process(unsigned   long n)
{
    unsigned   long i = 0;
    unsigned   long nCount = 0;
    unsigned   long nTemp = 0;

    unsigned    nCol = 0;

    for(i = 1; i <= MAX_I; i++)
    {
        nTemp = getDigits(i);
        nCount += nTemp;

        if(n <= nCount && nCount > nCount - nTemp)
            break;
    }

    nCol = n - (nCount - nTemp);
    printf("%ld\r\n", getLenOfN(nCol));
}

int getLocate(int n)
{
    return n;
}

int main()
{
    unsigned   long n = 0, i = 0;
    unsigned   long iLocate = 0;
    //freopen("bin\\debug\\in.txt", "r", stdin);

    scanf("%ld", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%ld", &iLocate);
        process(iLocate);
    }
    return 0;
}
